package cn.edu.scau.cmi.xiaowenyang.client;
import cn.edu.scau.cmi.xiaowenyang.multitonPattern.PokemonTeam;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class MultitonPatternClient extends Application{

	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		primaryStage.setTitle("多例模式");
        Pane pane = new Pane();
        Button button = new Button("添加");
        TextArea textArea = new TextArea();
        TextField textField = new TextField();
        button.setOnMouseClicked(new EventHandler<MouseEvent>() {
			@Override
			public void handle(MouseEvent event) {
				// TODO Auto-generated method stub
				textArea.clear();
				String str = textField.getText();
				if (PokemonTeam.add(str)){
					textArea.appendText("添加成功\n");
				} else {
					textArea.appendText("队伍中宝可梦数量已满\n");
				}
				textArea.appendText("此时队伍的宝可梦有：\n");
				for (String name:PokemonTeam.getPokemonTeam()){
					textArea.appendText(name+'\n');
				}
			}

        });

        button.setLayoutX(600);button.setLayoutY(100);

        textArea.setPrefHeight(300);
        textArea.setPrefWidth(500);
        textArea.setLayoutX(0); textArea.setLayoutY(0);
        textArea.setEditable(false);

        textField.setLayoutX(550); textField.setLayoutY(50);

        pane.getChildren().addAll(textArea,button,textField);
        primaryStage.setScene(new Scene(pane, 700, 500));
        primaryStage.show();
	}
}
